<template>
  <section>
    <main-bar></main-bar>
    <h3>read holder</h3>
    <div>
      <p>文档</p>
      <span v-for="(fima, i) in filesNma" :key="i">{{fima}}，</span>
    </div>
    <div>
      <p>文件夹</p>
      <span v-for="(fima, i) in rootDir" :key="i">{{fima}}，</span>
    </div>
  </section>
</template>

<script>
let path = require('path')
var fs = require('fs')
// var join = require('path').join
export default {
  name: 'readholder',
  data () {
    return {
      state: '0',
      filesNma: ['1', '2'],
      rootDir: ['1', '2']
    }
  },
  mounted () {
    console.log(__dirname) // 当前文件所在的绝对路径。
    console.log(__filename) // 当前文件的文件名,包括全路径。  __dirname和__filename都是全局对象。
    let pathtt = path.resolve(__dirname, './')
    let patht = path.resolve(__dirname, '/')
    console.log('pathtt', pathtt)
    console.log('patht', patht)
    this.init()
  },
  methods: {
    init () {
      const filePath = fs.readdirSync('./')
      let rootFileList = []
      let rootDirList = []
      filePath.forEach((item, index) => {
        fs.stat(item, (err, statSync) => {
          if (err) {
            throw err
          }
          let fsStats = fs.statSync(item)
          if (fsStats.isFile()) {
            rootFileList.push(item)
          } else if (fsStats.isDirectory()) {
            rootDirList.push(item)
          }
        })
      })
      this.filesNma = rootFileList
      this.rootDir = rootDirList
    },
    findJsonFile () {
      // let jsonFiles = []
      // let files = fs.readdirSync('./')
      // files.forEach(function (item, index) {
      //   let fPath = join('./', item)
      //   let stat = fs.statSync(fPath)
      //   // if (stat.isDirectory() === true) {
      //   //   this.findJsonFile(fPath)
      //   // }
      //   if (stat.isFile() === true) {
      //     jsonFiles.push(fPath)
      //   }
      // })
      // console.log(files)
    }
  }
}
</script>